package com.alen.sun.dao;

import com.alen.sun.bean.Package;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PackageMapper {
    //添加套餐
    @Insert("INSERT INTO package (packageId, package_name, package_description, package_price, package_type, package_image)" +
            "VALUES (#{packageId},#{packageName},#{packageDescription},#{packagePrice},#{packageType},#{packageImage})")
    Boolean addPackage(Package package1);

    //修改套餐
    @Update("UPDATE package SET package_name = #{packageName}, package_description = #{packageDescription},package_price = #{packagePrice},package_type = #{packageType},package_image = #{packageImage} WHERE packageId = #{packageId}")
    Boolean updatePackage(Package package1);

    //删除套餐
    @Delete("DELETE FROM package WHERE packageId = #{packageId}")
    Boolean deletePackage(Package package1);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select count(*) from package")
    Long count();

    /**
     * 分页查询,获取列表数据
     * @param start
     * @param pageSize
     * @return
     */
    @Select("select * from package limit #{start},#{pageSize}")
    List<Package> page(Integer start, Integer pageSize);

    //批量删除
    @Delete({
            "<script>",
            "delete from package where packageId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    Boolean deleteByIds(List<String> ids);

    //根据id查找记录--判断是否存在数据
    @Select("SELECT count(*) FROM package WHERE packageId = #{packageId}")
    Integer selectById(String packageId);

    //查出对应的数据根据id
    @Select("SELECT * FROM package WHERE packageId = #{packageId}")
    Package selectByPackageId(String packageId);

}
